package cn.com.liuxiaoluxx.cloud.api.config;


import com.alibaba.dubbo.config.annotation.Reference;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.com.liuxiaoluxx.cloud.api.interceptor.AuthHandlerInterceptor;
import cn.com.liuxiaoluxx.cloud.facade.service.user.UserService;

/**
 * 交给shiro验证
 */
// @Configuration
public class AuthConfig implements WebMvcConfigurer {

    @Reference(version = "1.0.0")
    private UserService userService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new AuthHandlerInterceptor(stringRedisTemplate));
        // 默认所有接口需要认证
        registration.addPathPatterns("/users/**");

        // 排除登录接口
        registration.excludePathPatterns("/users/login");
    }
}
